class Solution {
public:
    bool hasAlternatingBits(int n) {
        long tmp;
        tmp=n^(n>>1);
        return tmp&(tmp+1)?false:true;
    }
};
